package com.lk.demo.controller;


import com.lk.demo.model.Classes;
import com.lk.demo.model.Student;
import com.lk.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {
    private  StudentService studentService;
    @Autowired
    public StudentController(StudentService studentService)
    {
        this.studentService = studentService;
    }

    @GetMapping("/{id}")
    public Student getStudent(@PathVariable Long id){
        return studentService.getStudent(id);
    }

    @PostMapping("")
    public Student createStudent(@RequestBody  Student student){
       return  studentService.saveStudent(student);
    }

    @DeleteMapping
    public String deleteStudent(@RequestParam Long id){
         studentService.deleteStudent(id);
         return "success";
    }
    @PostMapping("/classes")
    public Classes createClass(@RequestBody Classes classes){
        return  studentService.saveClasses(classes);
    }

    @PutMapping("/{studentId}/classes/{classId}")
    public Student addStudentToClass(@PathVariable Long studentId, @PathVariable Long classId){
        return studentService.addToClasses(studentId, classId);
    }

}
